{% import 'macro.html.twig' as web_macro %}

{% set resultStatus = [] %}
{% include 'testpaper/manage/result-list-search-form.html.twig' %}

{% if paperResults %}

<table class="table table-striped table-hover">
  <thead>
    <tr>
      <th>{{'course.homework_check.review.name'|trans}}</th>
      <th>{{'course.homework_check.review.score'|trans}}</th>
      <th>{{'course.homework_check.review.submit_time'|trans}}</th>
      <th>{{'course.homework_check.review.status'|trans}}</th>
      <th>{{'course.homework_check.review.reviewer'|trans}}</th>
      <th>{{'course.homework_check.review.operation'|trans}}</th>
    </tr>
  </thead>
  <tbody>
    {% for paperResult in paperResults %}
      {% set student = users[paperResult.userId]|default(null) %}
      <tr>
        <td>{% if student %}{{ student.nickname }}{% else %}{{'site.data.empty'|trans}}{% endif %}</td>
        <td>
          {% if paperResult.status == 'finished' %}
            {% if paperResult.type == 'testpaper' %}
              {{ paperResult.score }}/{{ testpaper.score }}
            {% elseif paperResult.type == 'homework' %}
              {{ dict_text('passedStatus',paperResult.passedStatus) }}
            {% endif %}
          {% else %} -- {% endif %}
        </td>
        <td>{% if paperResult.status != 'doing' %}{{ paperResult.endTime|date('Y-m-d H:i:s') }}{% else %}{% endif %}</td>
        <td>
          {% if paperResult.status == 'doing' %}
            <span class="color-danger">{{'site.default.doing'|trans}}</span>
          {% elseif paperResult.status == 'reviewing' %}
            <span class="color-warning">{{'site.default.unreviewing'|trans}}</span>
          {% else %}
            <span class="color-primary">{{'site.default.reviewing'|trans}}</span>
          {% endif %}
        </td>
        {% if paperResult.status == 'finished' %}
          {% set teacher = users[paperResult.checkTeacherId]|default(null) %}
          <td>{% if teacher %}{{ teacher.nickname }}{% else %}{{ 'course.homework_check.review.system_review'|trans }}{% endif %}</td>
        {% else %}
          <td> -- </td>
        {% endif %}

        <td>
          {% if paperResult.status == 'finished' %}
            <a class="link-primary" href="{{ path(paperResult.type ~ '_result_show',{resultId:paperResult.id,action:'check'}) }}" id="show_testpaper_result" target="_blank">{{'course.homework_check.review.view_result_btn'|trans}}</a>
          {% elseif paperResult.status == 'reviewing' %}
            {% if isTeacher is defined and isTeacher %}
              {% if source == 'classroom' %}
                {% set checkUrl = path('classroom_manage_' ~ paperResult.type ~ '_check', {id:targetId,resultId:paperResult.id,action:'check'}) %}
              {% else %}
                {% set checkUrl = path('course_manage_' ~ paperResult.type ~ '_check', {id:targetId,resultId:paperResult.id,action:'check'}) %}
              {% endif %}
              <a class="btn btn-default btn-sm " href="{{ checkUrl }}"  target="_blank">{{'course.homework_check.review_btn'|trans}}</a>
            {% else %}
              <a class="btn btn-default btn-sm disabled" href="javascript;;">{{'course.homework_check.review_btn'|trans}}</a>
            {% endif %}
          {% endif %}
        </td>
      </tr>
    {% endfor %}
  </tbody>
</table>

{% else %}
  <div class="empty">{{'course.homework_check.review.empty'|trans}}</div>
{% endif %}

<nav class="text-center">
  {{ web_macro.paginator(paginator) }}
</nav>
